Return to start page

Systems/Character/Struct Class Selection.j

Code

		
1			library AStructSystemsCharacterClassSelection requires optional ALibraryCoreDebugMisc, AStructCoreGeneralHashTable, ALibraryCoreGeneralPlayer, ALibraryCoreInterfaceCinematic, ALibraryCoreInterfaceMisc, ALibraryCoreInterfaceMultiboard, AStructSystemsCharacterCharacter, AStructSystemsCharacterClass
2
3 /// @todo Should be a part of @struct AClassSelection, vJass bug.
4 function interface AClassSelectionSelectClassAction takes ACharacter character, AClass class returns nothing
5
6 /// @todo Should be a part of @struct AClassSelection, vJass bug.
7 function interface AClassSelectionStartGameAction takes nothing returns nothing
8
9 struct AClassSelection
10 //static constant members
11 private static constant integer maxInfoSheetItems = 4 + 12 + 1 + 8 //4 + AClass.maxAbilities + 1 + AClass.maxDescriptionLines
12 private static constant integer maxInfoSheetIconItems = 4 + 12 //4 + AClass.maxAbilities
13 //static start members
14 private static camerasetup m_cameraSetup
15 private static real m_x
16 private static real m_y
17 private static real m_facing
18 private static real m_refreshRate
19 private static real m_rotationAngle
20 private static AClass m_firstClass
21 private static AClass m_lastClass
22 private static AClassSelectionStartGameAction m_startGameAction
23 private static string m_strengthIconPath
24 private static string m_agilityIconPath
25 private static string m_intelligenceIconPath
26 private static string m_textTitle
27 private static string m_textStrength
28 private static string m_textAgility
29 private static string m_textIntelligence
30 private static string m_textAbilities
31 private static string m_textDescription
32 //static members
33 private static integer m_stack //required for the start game action
34 //start members
35 private player m_user
36 private real m_startX
37 private real m_startY
38 private real m_startFacing
39 private AClassSelectionSelectClassAction m_selectClassAction
40 //members
41 private unit m_classUnit
42 private trigger m_leaveTrigger
43 private trigger m_refreshTrigger
44 private trigger m_changePreviousTrigger
45 private trigger m_changeNextTrigger
46 private trigger m_selectTrigger
47 private multiboard m_infoSheet
48 private AClass m_class
49
50 //! runtextmacro optional A_STRUCT_DEBUG("\"AClassSelection\"")
51
52 //methods
53
54 public method show takes nothing returns nothing
55 if (GetPlayerController(this.m_user) == MAP_CONTROL_COMPUTER or GetPlayerSlotState(this.m_user) == PLAYER_SLOT_STATE_LEFT) then
56 call this.selectRandomClass()
57 else
58 call ClearScreenMessagesForPlayer(this.m_user)
59 call SetUserInterfaceForPlayer(this.m_user, false, true)
60 call ShowMultiboardForPlayer(this.m_user, this.m_infoSheet, true)
61 call MultiboardMinimize(this.m_infoSheet, false)
62 call this.createUnit()
63 endif
64 endmethod
65
66 //get new test
67 private method refreshInfoSheet takes nothing returns nothing
68 local integer i
69 local multiboarditem multiboardItem
70 call MultiboardSetTitleText(this.m_infoSheet, IntegerArg(IntegerArg(StringArg(thistype.m_textTitle, GetUnitName(this.m_classUnit)), this.m_class), thistype.m_lastClass - thistype.m_firstClass + 1))
71 //strength
72 set multiboardItem = MultiboardGetItem(this.m_infoSheet, 0, 0)
73 call MultiboardSetItemValue(multiboardItem, thistype.m_textStrength + ": " + I2S(GetHeroStr(this.m_classUnit, false)))
74 call MultiboardReleaseItem(multiboardItem)
75 set multiboardItem = null
76 //agility
77 set multiboardItem = MultiboardGetItem(this.m_infoSheet, 1, 0)
78 call MultiboardSetItemValue(multiboardItem, thistype.m_textAgility + ": " + I2S(GetHeroAgi(this.m_classUnit, false)))
79 call MultiboardReleaseItem(multiboardItem)
80 set multiboardItem = null
81 //intelligence
82 set multiboardItem = MultiboardGetItem(this.m_infoSheet, 2, 0)
83 call MultiboardSetItemValue(multiboardItem, thistype.m_textIntelligence + ": " + I2S(GetHeroInt(this.m_classUnit, false)))
84 call MultiboardReleaseItem(multiboardItem)
85 set multiboardItem = null
86 //abilities
87 set i = 4
88 loop
89 exitwhen(i == thistype.maxInfoSheetIconItems)
90 set multiboardItem = MultiboardGetItem(this.m_infoSheet, i, 0)
91 if (this.m_class.ability(i - 4) != 0) then
92 call MultiboardSetItemIcon(multiboardItem, this.m_class.abilityIconPath(i - 4))
93 call MultiboardSetItemValue(multiboardItem, GetObjectName(this.m_class.ability(i - 4)))
94 call MultiboardSetItemStyle(multiboardItem, true, true)
95 else
96 call MultiboardSetItemStyle(multiboardItem, false, false)
97 endif
98 call MultiboardReleaseItem(multiboardItem)
99 set multiboardItem = null
100 set i = i + 1
101 endloop
102 //description
103 set i = thistype.maxInfoSheetIconItems + 1
104 loop
105 exitwhen(i == thistype.maxInfoSheetItems)
106 set multiboardItem = MultiboardGetItem(this.m_infoSheet, i, 0)
107 if (StringLength(this.m_class.descriptionLine(i - thistype.maxInfoSheetIconItems + 1)) > 0) then
108 call MultiboardSetItemValue(multiboardItem, this.m_class.descriptionLine(i - thistype.maxInfoSheetIconItems + 1))
109 call MultiboardSetItemStyle(multiboardItem, true, false)
110 else
111 call MultiboardSetItemStyle(multiboardItem, false, false)
112 endif
113 call MultiboardReleaseItem(multiboardItem)
114 set multiboardItem = null
115 set i = i + 1
116 endloop
117 endmethod
118
119 private method createUnit takes nothing returns nothing
120 local integer i
121 local player user
122 if (this.m_classUnit != null) then
123 call RemoveUnit(this.m_classUnit)
124 set this.m_classUnit = null
125 endif
126 set this.m_classUnit = CreateUnit(this.m_user, this.m_class.unitType(), thistype.m_x, thistype.m_y, thistype.m_facing)
127 call SetUnitInvulnerable(this.m_classUnit, true)
128 call PauseUnit(this.m_classUnit, true)
129 call SetUnitPathing(this.m_classUnit, false)
130 //refresh position
131 call SetUnitX(this.m_classUnit, thistype.m_x)
132 call SetUnitY(this.m_classUnit, thistype.m_y)
133 //Für andere Spieler unsichtbar machen
134 set i = 0
135 loop
136 exitwhen (i == bj_MAX_PLAYERS)
137 set user = Player(i)
138 if (user != this.m_user and IsPlayerPlayingUser(user)) then
139 call UnitShareVision(this.m_classUnit, user, false)
140 endif
141 set user = null
142 set i = i + 1
143 endloop
144 call SetUnitAnimation(this.m_classUnit, this.m_class.animation())
145 call PlaySoundPathForPlayer(this.m_user, this.m_class.soundPath())
146 //call SetCameraTargetControllerNoZForPlayer(this.user, this.classUnit, 0.0, 0.0, false)
147
148 call this.refreshInfoSheet()
149 endmethod
150
151 private method selectClass takes nothing returns nothing
152 local ACharacter character = ACharacter.setPlayerCharacter(this.m_user, this.m_class.generateUnit(this.m_user, this.m_startX, this.m_startY, this.m_startFacing))
153 if (GetPlayerController(this.m_user) == MAP_CONTROL_COMPUTER or (GetPlayerSlotState(this.m_user) == PLAYER_SLOT_STATE_LEFT and ACharacter.shareOnPlayerLeaves())) then
154 call character.shareControl(true)
155 endif
156 call SetUserInterfaceForPlayer(this.m_user, false, false)
157 call ResetToGameCameraForPlayer(this.m_user, 0.0)
158 //call PanCameraToForPlayer(this.m_user, this.m_startX, this.m_startY) ///WAAAAA
159 call character.setClass(this.m_class)
160 call this.m_selectClassAction.execute(character, this.m_class)
161 call this.destroy()
162 endmethod
163
164 private method selectRandomClass takes nothing returns nothing
165 set this.m_class = GetRandomInt(thistype.m_firstClass, thistype.m_lastClass)
166 call this.selectClass()
167 endmethod
168
169 private static method triggerActionPlayerLeaves takes nothing returns nothing
170 local trigger triggeringTrigger = GetTriggeringTrigger()
171 local thistype this = AHashTable.global().handleInteger(triggeringTrigger, "this")
172 local player whichPlayer
173 local integer i
174 if (ACharacter.shareOnPlayerLeaves()) then
175 set i = 0
176 loop
177 exitwhen (i == bj_MAX_PLAYERS)
178 if (i != GetPlayerId(this.m_user)) then
179 set whichPlayer = Player(i)
180 call SetPlayerAlliance(this.m_user, whichPlayer, ALLIANCE_SHARED_CONTROL, true)
181 set whichPlayer = null
182 endif
183 set i = i + 1
184 endloop
185 endif
186 if (ACharacter.destroyOnPlayerLeaves()) then
187 call this.destroy()
188 else
189 call this.selectClass()
190 endif
191 set triggeringTrigger = null
192 endmethod
193
194 private method createLeaveTrigger takes nothing returns nothing
195 local event triggerEvent
196 local triggeraction triggerAction
197 set this.m_leaveTrigger = CreateTrigger()
198 set triggerEvent = TriggerRegisterPlayerEvent(this.m_leaveTrigger, this.m_user, EVENT_PLAYER_LEAVE)
199 set triggerAction = TriggerAddAction(this.m_leaveTrigger, function thistype.triggerActionPlayerLeaves)
200 call AHashTable.global().setHandleInteger(this.m_leaveTrigger, "this", this)
201 set triggerEvent = null
202 set triggerAction = null
203 endmethod
204
205 private static method triggerActionRefresh takes nothing returns nothing
206 local trigger triggeringTrigger = GetTriggeringTrigger()
207 local thistype this = AHashTable.global().handleInteger(triggeringTrigger, "this")
208 debug if (thistype.m_cameraSetup != null) then
209 call CameraSetupApplyForPlayer(true, thistype.m_cameraSetup, this.m_user, 0.0)
210 debug else
211 debug call this.print("No camera object.")
212 debug endif
213 call SetUnitFacingTimed(this.m_classUnit, GetUnitFacing(this.m_classUnit) + thistype.m_rotationAngle, thistype.m_refreshRate)
214 set triggeringTrigger = null
215 endmethod
216
217 private method createRefreshTrigger takes nothing returns nothing
218 local event triggerEvent
219 local triggeraction triggerAction
220 if (thistype.m_refreshRate > 0.0) then
221 set this.m_refreshTrigger = CreateTrigger()
222 set triggerEvent = TriggerRegisterTimerEvent(this.m_refreshTrigger, thistype.m_refreshRate, true)
223 set triggerAction = TriggerAddAction(this.m_refreshTrigger, function thistype.triggerActionRefresh)
224 call AHashTable.global().setHandleInteger(this.m_refreshTrigger, "this", this)
225 set triggerEvent = null
226 set triggerAction = null
227 endif
228 endmethod
229
230 private static method triggerActionChangeToPrevious takes nothing returns nothing
231 local trigger triggeringTrigger = GetTriggeringTrigger()
232 local thistype this = AHashTable.global().handleInteger(triggeringTrigger, "this")
233 if (this.m_class == thistype.m_firstClass) then
234 set this.m_class = thistype.m_lastClass
235 else
236 set this.m_class = this.m_class - 1
237 endif
238 call this.createUnit()
239 set triggeringTrigger = null
240 endmethod
241
242 private method createChangePreviousTrigger takes nothing returns nothing
243 local event triggerEvent
244 local triggeraction triggerAction
245 set this.m_changePreviousTrigger = CreateTrigger()
246 set triggerEvent = TriggerRegisterKeyEventForPlayer(this.m_user, this.m_changePreviousTrigger, AKeyLeft, true)
247 set triggerAction = TriggerAddAction(this.m_changePreviousTrigger, function thistype.triggerActionChangeToPrevious)
248 call AHashTable.global().setHandleInteger(this.m_changePreviousTrigger, "this", this)
249 set triggerEvent = null
250 set triggerAction = null
251 endmethod
252
253 private static method triggerActionChangeToNext takes nothing returns nothing
254 local trigger triggeringTrigger = GetTriggeringTrigger()
255 local thistype this = AHashTable.global().handleInteger(triggeringTrigger, "this")
256 if (this.m_class == thistype.m_lastClass) then
257 set this.m_class = thistype.m_firstClass
258 else
259 set this.m_class = this.m_class + 1
260 endif
261 call this.createUnit()
262 set triggeringTrigger = null
263 endmethod
264
265 private method createChangeNextTrigger takes nothing returns nothing
266 local event triggerEvent
267 local triggeraction triggerAction
268 set this.m_changeNextTrigger = CreateTrigger()
269 set triggerEvent = TriggerRegisterKeyEventForPlayer(this.m_user, this.m_changeNextTrigger, AKeyRight, true)
270 set triggerAction = TriggerAddAction(this.m_changeNextTrigger, function thistype.triggerActionChangeToNext)
271 call AHashTable.global().setHandleInteger(this.m_changeNextTrigger, "this", this)
272 set triggerEvent = null
273 set triggerAction = null
274 endmethod
275
276 private static method triggerActionSelectClass takes nothing returns nothing
277 local trigger triggeringTrigger = GetTriggeringTrigger()
278 local thistype this = AHashTable.global().handleInteger(triggeringTrigger, "this")
279 call this.selectClass()
280 set triggeringTrigger = null
281 endmethod
282
283 private method createSelectTrigger takes nothing returns nothing
284 local event triggerEvent
285 local triggeraction triggerAction
286 set this.m_selectTrigger = CreateTrigger()
287 set triggerEvent = TriggerRegisterKeyEventForPlayer(this.m_user, this.m_selectTrigger, AKeyEscape, true)
288 set triggerAction = TriggerAddAction(this.m_selectTrigger, function thistype.triggerActionSelectClass)
289 call AHashTable.global().setHandleInteger(this.m_selectTrigger, "this", this)
290 set triggerEvent = null
291 set triggerAction = null
292 endmethod
293
294 //release test
295 private method createInfoSheet takes nothing returns nothing
296 local integer i
297 local multiboarditem multiboardItem
298 set this.m_infoSheet = CreateMultiboard()
299 call MultiboardSetColumnCount(this.m_infoSheet, 1)
300 call MultiboardSetRowCount(this.m_infoSheet, thistype.maxInfoSheetItems)
301 set i = 0
302 loop
303 exitwhen (i == thistype.maxInfoSheetItems)
304 set multiboardItem = MultiboardGetItem(this.m_infoSheet, i, 0)
305 if (i < thistype.maxInfoSheetIconItems) then
306 call MultiboardSetItemStyle(multiboardItem, true, true)
307 else
308 call MultiboardSetItemStyle(multiboardItem, true, false)
309 endif
310 call MultiboardReleaseItem(multiboardItem)
311 set multiboardItem = null
312 set i = i + 1
313 endloop
314 call MultiboardSetItemsWidth(this.m_infoSheet, 0.20)
315
316 //strength
317 set multiboardItem = MultiboardGetItem(this.m_infoSheet, 0, 0)
318 call MultiboardSetItemIcon(multiboardItem, thistype.m_strengthIconPath)
319 call MultiboardReleaseItem(multiboardItem)
320 set multiboardItem = null
321 //agility
322 set multiboardItem = MultiboardGetItem(this.m_infoSheet, 1, 0)
323 call MultiboardSetItemIcon(multiboardItem, thistype.m_agilityIconPath)
324 call MultiboardReleaseItem(multiboardItem)
325 set multiboardItem = null
326 //intelligence
327 set multiboardItem = MultiboardGetItem(this.m_infoSheet, 2, 0)
328 call MultiboardSetItemIcon(multiboardItem, thistype.m_intelligenceIconPath)
329 call MultiboardReleaseItem(multiboardItem)
330 set multiboardItem = null
331 //abilities
332 set multiboardItem = MultiboardGetItem(this.m_infoSheet, 3, 0)
333 call MultiboardSetItemValue(multiboardItem, thistype.m_textAbilities + ": ")
334 call MultiboardReleaseItem(multiboardItem)
335 set multiboardItem = null
336 //description
337 set multiboardItem = MultiboardGetItem(this.m_infoSheet, thistype.maxInfoSheetIconItems, 0)
338 call MultiboardSetItemValue(multiboardItem, thistype.m_textDescription + ": ")
339 call MultiboardReleaseItem(multiboardItem)
340 set multiboardItem = null
341 endmethod
342
343 public static method create takes player user, real startX, real startY, real startFacing, AClassSelectionSelectClassAction selectClassAction returns thistype
344 local thistype this = thistype.allocate()
345 //start members
346 set this.m_user = user
347 set this.m_startFacing = startFacing
348 set this.m_startX = startX
349 set this.m_startY = startY
350 set this.m_selectClassAction = selectClassAction
351 //members
352 set this.m_class = thistype.m_firstClass
353 //static members
354 set thistype.m_stack = thistype.m_stack + 1
355
356 call this.createLeaveTrigger()
357 call this.createRefreshTrigger()
358 call this.createChangePreviousTrigger()
359 call this.createChangeNextTrigger()
360 call this.createSelectTrigger()
361 call this.createInfoSheet()
362 return this
363 endmethod
364
365 private method destroyLeaveTrigger takes nothing returns nothing
366 call AHashTable.global().destroyTrigger(this.m_leaveTrigger)
367 set this.m_leaveTrigger = null
368 endmethod
369
370 private method destroyRefreshTrigger takes nothing returns nothing
371 call AHashTable.global().destroyTrigger(this.m_refreshTrigger)
372 set this.m_refreshTrigger = null
373 endmethod
374
375 private method destroyChangePreviousTrigger takes nothing returns nothing
376 call AHashTable.global().destroyTrigger(this.m_changePreviousTrigger)
377 set this.m_changePreviousTrigger = null
378 endmethod
379
380 private method destroyChangeNextTrigger takes nothing returns nothing
381 call AHashTable.global().destroyTrigger(this.m_changeNextTrigger)
382 set this.m_changeNextTrigger = null
383 endmethod
384
385 private method destroySelectTrigger takes nothing returns nothing
386 call AHashTable.global().destroyTrigger(this.m_selectTrigger)
387 set this.m_selectTrigger = null
388 endmethod
389
390 private method destroyInfoSheet takes nothing returns nothing
391 call DestroyMultiboard(this.m_infoSheet)
392 set this.m_infoSheet = null
393 endmethod
394
395 private method removeClassUnit takes nothing returns nothing
396 call RemoveUnit(this.m_classUnit)
397 set this.m_classUnit = null
398 endmethod
399
400 private method onDestroy takes nothing returns nothing
401 //start members
402 set this.m_user = null
403 //static members
404 set thistype.m_stack = thistype.m_stack - 1
405
406 call this.destroyLeaveTrigger()
407 call this.destroyRefreshTrigger()
408 call this.destroyChangePreviousTrigger()
409 call this.destroyChangeNextTrigger()
410 call this.destroySelectTrigger()
411 call this.destroyInfoSheet()
412 call this.removeClassUnit()
413
414 if (thistype.m_stack == 0) then
415 call thistype.m_startGameAction.execute()
416 endif
417 endmethod
418
419 public static method init takes camerasetup cameraSetup, real x, real y, real facing, real refreshRate, real rotationAngle, AClass firstClass, AClass lastClass, AClassSelectionStartGameAction startGameAction, string strengthIconPath, string agilityIconPath, string intelligenceIconPath, string textTitle, string textStrength, string textAgility, string textIntelligence, string textAbilities, string textDescription returns nothing
420 //static start members
421 set thistype.m_cameraSetup = cameraSetup
422 set thistype.m_x = x
423 set thistype.m_y = y
424 set thistype.m_facing = facing
425 set thistype.m_refreshRate = refreshRate
426 set thistype.m_rotationAngle = rotationAngle
427 set thistype.m_firstClass = firstClass
428 set thistype.m_lastClass = lastClass
429 set thistype.m_startGameAction = startGameAction
430 set thistype.m_strengthIconPath = strengthIconPath
431 set thistype.m_agilityIconPath = agilityIconPath
432 set thistype.m_intelligenceIconPath = intelligenceIconPath
433 set thistype.m_textTitle = textTitle
434 set thistype.m_textStrength = textStrength
435 set thistype.m_textAgility = textAgility
436 set thistype.m_textIntelligence = textIntelligence
437 set thistype.m_textAbilities = textAbilities
438 set thistype.m_textDescription = textDescription
439 //static members
440 set thistype.m_stack = 0
441 endmethod
442 endstruct
443
444 endlibrary